// page_other/zdysdk/zdysdk.js
let app = getApp()
let yuming = app.globalData.yuming
var shuzong = []
var shu = []
const request = require('../../config/request');
const amapFile = require('../../config/amap-wx.130.js'); //高德js
const config = require('../../config/config.js'); //引用我们的配置文件
Page({
  ...request,
  /**
   * 页面的初始数据
   */
  data: {
    yuming: yuming,
    heights: "",
    title: "执业药师打卡",
    buttonClicked: false,
    day: '',
    gongwu: false,
    page: 1,
    shopName: '',
    id: '',
    yuangong: '',
    latitude: '', //打卡人所在纬度
    longitude: '', //打卡人所在经度
    signaddress: '', //打卡人所在具体位置
    shop_lat: '', //店铺所在纬度
    shop_lng: '', //店铺所在经度
    isQian: false,
    //日历
    days: [],
    dakalist: [],
    cur_year: 0,
    cur_month: 0,
    keda: false,
    kedas: false,
    dakajl: '', //打卡距离
    dayList: [], //当天的两条记录
    zao_issign: '', //0未1已
    wan_issign: '', //0未1已
 
    bushuo: '',
    dakatiqi: '',
    cur_month: '', //月
    cur_year: '', //年
    photo: [],
    wuphoto: '',
    jilulist: [],
    isshou: false,
    daySign: '', //打卡次数
    zongtim: '', //第一次打卡时间
    jieshutime: '', //离第一次打卡 四小时 后的时间
    daysaa: '00', //天
    hours: '00', //时
    minutes: '00', //分
    seconds: '00', //秒
    countdown: '',
    // 定位信息
    dakalatitude:'',//纬度
    dakalongitude:'',//经度
    NowAddress:'',//当前定位到的位置
    bangd:0,//如果授权显示页面==1,否则不显示
    daka_length:0,//店铺允许打卡的范围
    Isdaka:false,//是否允许打卡
    xukekaishi: '2020-01-01',
    starTime:'请选择开始时间',
    endTime:'请选择结束时间',
    isbu: false,//未打卡弹窗
    weidakaText:'',//未打卡说明文字
    dakaTablist:['打卡记录','未打卡记录'],
    cutterIndex:0,
  },

  // 未打卡开始时间
  changeStart: function (e) {
    this.setData({
      starTime: e.detail.value
    })
  },
  // 结束
  changeEnd: function (e) {
    this.setData({
      endTime: e.detail.value
    })
  },
  // 未打卡说明文字
  bindsh(e){
    let value = e.detail.value;
    this.setData({
      weidakaText: value
    })
  },
    // 拍照上传
    // 上传
    chuan(e) {
      var that = this
      var pics = [];
      var wuphoto = this.data.wuphoto;
      this.myChooseImage(9).then(res => {
          const tempFilePaths = res.tempFilePaths
          for (var i = 0; i < tempFilePaths.length; i++) {
              pics.push(tempFilePaths[i])
          }
          if ((pics.length) + (that.data.photo.length) > 9) {
              wx.showToast({
                  title: '最多可上传' + 9 + "张",
                  icon: 'none'
              })
          } else {
              for (var i = 0; i < tempFilePaths.length; i++) {
                  (function (i) { // 注意这里是形参
                      setTimeout(function () {
                          that.wuduoupimg(tempFilePaths[i]).then(res => {
                              var data = JSON.parse(res.data)
                              var urls = data.httpUrl + data.imgUrl
                              wuphoto = wuphoto.concat(data.imgUrl + ",")
                              that.setData({
                                  photo: that.data.photo.concat(urls),
                                  wuphoto: wuphoto
                              });
                          })
                      }, 800 * i); // 还是每秒执行一次，不是累加的
                  })(i) // 注意这里是实参，这里把要用的参数传进去
              }
          }
      })
  },
    // 差掉
    chadiao(e) {
      var index = e.currentTarget.dataset.index
      var photo = this.data.photo;
      var wuphoto = this.data.wuphoto;
      var dd = wuphoto.split(",")
      console.log(dd)
      photo.splice(index, 1)
      dd.splice(index, 1)
      var rr = dd.join(",")
      this.setData({
          photo: photo,
          wuphoto: rr
      })
  },
  // 提交未打卡说明
  quedbu(){
    var that = this
    var data = {
      staffid: that.data.id,
      shopId: wx.getStorageSync('shopIds'),
      signtime: that.data.starTime,
      endtime: that.data.endTime,
      notexplain: that.data.weidakaText,
      explain_image: that.data.wuphoto,
    }
    this.myRequest(yuming + 'Jinghexincheng/staff_nosignlog_add', data
    , 'POST').then(res => {
      wx.hideLoading();
      if (res.data.code == 200) {
        that.wxsT(res.data.msg)
        that.setData({
          isbu:false,
          signtime: '',
          endtime: '',
          notexplain: '',
          explain_image: '',
        })
      }
    })
  },
  // 预览图片
  fangda(e) {
    var url = e.currentTarget.dataset.url
    console.log('点击了放大！')
    wx.previewImage({
        urls: [url]
    })
},
  // 选择是否打卡选项卡
  chanegcuIndex(e){
    var index = e.currentTarget.dataset.index
    this.setData({
      cutterIndex: index,
      page:1,
      dakalist:[]
    })
    if(index==0){
      this.getdkList()
    }else if(index==1){
      this.getWedkList()
    }
  },
  // 判断是否签到
  isQiandao() {
    let that = this
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    // shop_staff_yaoshi_notOryes
    // shop_staff_yaoshi_notOryes_bug
    this.myRequest(yuming + 'shop/shop_staff_yaoshi_notOryes', {
      shopId: wx.getStorageSync('shopIds'),
      staffid: that.data.id
    }, 'POST').then(res => {
      wx.hideLoading();
      console.log(res)
      if (res.data.code == 200) {
        this.setData({
          // isQian: res.data.daySign, //0未打卡 1打卡一次 2打卡两次
          zao_issign: res.data.zao_issign, //0未打卡 1打卡
          wan_issign: res.data.wan_issign,
          dayList: res.data.dayList,
          jilulist: res.data.data,
          daySign: res.data.daySign, //打卡次数
          isQian: res.data.isQian//是否允许签到
        })
        this.onJudgeSign();  //匹配判断当月与当月哪些日子签到打卡
        var zongtim = res.data.dayList[0].createtime
        var jieshutime = res.data.fourTime
        if (this.data.daySign == 1 && !this.data.isQian) {
          this.setData({
            zongtim: zongtim,
            jieshutime: jieshutime,
          })
          this.countTime()
        }

      }
    })
  },
  getxx() {
    let that = this
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    this.myRequest(yuming + 'shop/shopFindStaff', {
      id: that.data.id,
      // page:this.data.page,
      shopId: wx.getStorageSync('shopIds')
    }, 'POST').then(res => {
      wx.hideLoading();
      if (res.data.code == 200) {
        this.setData({
          yuangong: res.data.data
        })
      }
    })
  },
  // 获取店铺经纬度
  getshopjwd() {
    this.myRequest(yuming + 'Besall/findShopInfos', {
      shopId: wx.getStorageSync('shopIds')
    }, "POST").then(res => {
      if (res.data.code == 200) {
        this.setData({
          shop_lat: res.data.data.lat,
          shop_lng: res.data.data.lng,
          // daka_length: res.data.distance,//允许打卡的范围
          daka_length: 100,//允许打卡的范围
        //   daka_length: 2,
          shopName: res.data.data.shopName
        })
        // this.fanwei()//页面刚开始已经获取自己的位置,当前位置获取店铺的位置,fanwei计算两者之间的距离
      }
    })
  },


  // 判断是否在打卡范围
    fanwei() {
        var that = this
        var isQian  = that.data.isQian
        console.log('在范围内',isQian)//在范围但是4个小时前已经打过卡
    wx.hideLoading({
      success: (res) => {},
    })
    // dakalatitude:'',//纬度
    // dakalongitude:'',//经度
    var juli = this.getLength(this.data.dakalatitude, this.data.dakalongitude, this.data.shop_lat, this.data.shop_lng)
    console.log('计算打卡距离', juli,this.data.daka_length)
    if (juli > this.data.daka_length) {
  
      this.setData({
        buttonClicked: false
      })
      setTimeout(res=>{
        wx.showToast({
            title: '当前不在打卡范围内',
            icon: 'none',
            duration:2000,
          })
      },1000)
    } else {
        // 
        this.setData({
            buttonClicked: true
        })
      // this.daka();
    }
  },

  Rad(d) {
    //根据经纬度判断距离
    return d * Math.PI / 180.0;
  },
  // 计算距离
  getLength(lat1, lng1, lat2, lng2) {
    console.log(lat1, lng1, lat2, lng2)
    var La1 = lat1 * Math.PI / 180.0;
    var La2 = lat2 * Math.PI / 180.0;
    var La3 = La1 - La2;
    var Lb3 = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0;
    var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(La3 / 2), 2) + Math.cos(La1) * Math.cos(La2) * Math.pow(Math.sin(Lb3 / 2), 2)));
    s = s * 6378.137;
    s = Math.round(s * 10000) / 10000;
    s = s.toFixed(0);
    return s;

    // const PI = Math.PI
    // const EARTH_RADIUS = 6378137.0

    // function getRad(d) {
    //     return d * PI / 180.0
    // }
    // let f = getRad((lat1 + lat2) / 2)
    // let g = getRad((lat1 - lat2) / 2)
    // let l = getRad((lng1 - lng2) / 2)
    // let sg = Math.sin(g)
    // let sl = Math.sin(l)
    // let sf = Math.sin(f)
    // let s, c, w, r, d, h1, h2
    // let a = EARTH_RADIUS
    // let fl = 1 / 298.257
    // sg = sg * sg
    // sl = sl * sl
    // sf = sf * sf
    // s = sg * (1 - sl) + (1 - sf) * sl
    // c = (1 - sg) * (1 - sl) + sf * sl
    // w = Math.atan(Math.sqrt(s / c))
    // r = Math.sqrt(s * c) / w
    // d = 2 * w * a
    // h1 = (3 * r - 1) / 2 / c
    // h2 = (3 * r + 1) / 2 / s
    // return d * (1 + fl * (h1 * sf * (1 - sg) - h2 * (1 - sf) * sg))
  },


  // 打卡记录
  getdkList() {
    let that = this;
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    this.myRequest(yuming + 'shop/shop_staff_yaoshi_signlist', {
      staffid: that.data.id,
      page: that.data.page
    }, 'POST').then(res => {
      wx.hideLoading();
      if (res.data.code == 200) {
        shu = res.data.data
        shu.forEach(item => {
          let arr = item.createtime.split(/\s+/);
          item.time = arr[1]
        })
        if (that.data.page != 1) {
          if (shu.length != 10) {
            wx.showToast({
              title: '没有更多数据了~',
              icon: "none"
            })
            that.setData({
              gongwu: true
            })
          }
        }
        this.setData({
          dakalist: shuzong.concat(shu)
        })
      }
    })
  },
  // 未打卡记录
  getWedkList() {
    let that = this;
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    this.myRequest(yuming + 'Jinghexincheng/staff_nosignlog_list', {
      shopId: wx.getStorageSync('shopIds'), 
      staffid: that.data.id,
      page: that.data.page,
      signtime:'',
      endtime:'',
    }, 'POST').then(res => {
      wx.hideLoading();
      if (res.data.code == 200) {
        shu = res.data.data
        shu.forEach(item => {
          let arr = item.createtime.split(/\s+/);
          item.time = arr[1]
        })
        if (that.data.page != 1) {
          if (shu.length != 10) {
            wx.showToast({
              title: '没有更多数据了~',
              icon: "none"
            })
            that.setData({
              gongwu: true
            })
          }
        }
        this.setData({
          dakalist: shuzong.concat(shu)
        })
      }
    })
  },
   // 查看更多
  lookmore() {
    shuzong = this.data.dakalist
    this.setData({
      page: (this.data.page) + 1
    })
    this.getdkList();
  },

  // 获取当月共多少天
  getThisMonthDays: function (year, month) {
    return new Date(year, month, 0).getDate()
  },

  // 获取当月第一天星期几
  getFirstDayOfWeek: function (year, month) {
    return new Date(Date.UTC(year, month - 1, 1)).getDay();
  },

  // 计算当月1号前空了几个格子，把它填充在days数组的前面
  calculateEmptyGrids: function (year, month) {
    var that = this;
    //计算每个月时要清零
    that.setData({
      days: []
    });
    const firstDayOfWeek = this.getFirstDayOfWeek(year, month);
    if (firstDayOfWeek > 0) {
      for (let i = 0; i < firstDayOfWeek; i++) {
        var obj = {
          date: null,
          isSign: false
        }
        that.data.days.push(obj);
      }
      this.setData({
        days: that.data.days
      });
      //清空
    } else {
      this.setData({
        days: []
      });
    }
  },

  // 绘制当月天数占的格子，并把它放到days数组中
  calculateDays: function (year, month) {
    var that = this;
    const thisMonthDays = this.getThisMonthDays(year, month);
    for (let i = 1; i <= thisMonthDays; i++) {
      var obj = {
        date: i,
        isSign: false
      }
      that.data.days.push(obj);
    }
    this.setData({
      days: that.data.days
    });
  },
  
  //匹配判断当月与当月哪些日子签到打卡
  onJudgeSign: function () {
    wx.showLoading({
      title: '加载中',
    })
    var that = this;
    // var signs = that.data.dakalist;
    var signs = that.data.jilulist;
    var daysArr = that.data.days;
    for (var i = 0; i < signs.length; i++) {
      // console.log(signs[i].signtime.replace(/-/g, "/"));
      var current = new Date(signs[i].signtime.replace(/-/g, "/"));
      // console.log(signs[i].signtime)
      // console.log(current);
      var year = current.getFullYear();
      // console.log(year);
      var month = current.getMonth() + 1;
      // console.log(month);
      var day = current.getDate();
      // console.log(day);
      day = parseInt(day);
      // console.log(day);
      for (var j = 0; j < daysArr.length; j++) {
        //年月日相同并且已打卡
        if (year == that.data.cur_year && month == that.data.cur_month && daysArr[j].date == day) {
          daysArr[j].isSign = true;
        }
      }
    }
    that.setData({
      days: daysArr
    });
    wx.hideLoading({
      success: (res) => {},
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getLocation()  //  获取自己的经纬度  预处理信息
  
    console.log(options)
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5,
      // id: 238,
      id: options.id,
      // shopName: wx.getStorageSync('shopname'),

    })
    if (options.scene) {
      this.setData({
        shopId: options.scene
      })
    } else {
      this.setData({
        shopId: options.shopId
      })
    }
    wx.setStorageSync('shopIds', this.data.shopId)
    shuzong = [];
    shu = [];

    wx.showLoading({
      title: '加载中',
    })
    //获取当前年月
    const date = new Date();
    const cur_year = date.getFullYear();
    const cur_month = date.getMonth() + 1;
    const day = date.getDate();
    const hour = date.getHours()
    const minute = date.getMinutes()
    // var hour = 9
    this.setData({
      day: day,
      cur_year: cur_year,
      cur_month: cur_month,
    })
    if (hour >= 9 && hour < 10) {
      console.log("9点10点")
      this.setData({
        keda: true,
        kedas: false,
        dangtime: hour + ":" + minute,
        gutime: '09:00-10:00'
      })
    }
    if (hour >= 16 && hour < 17) {
      console.log("四点五点")
      this.setData({
        keda: false,
        kedas: true,
        dangtime: hour + ":" + minute,
        gutime: "16:00-17:00"
      })
    }
    const weeks_ch = ['日', '一', '二', '三', '四', '五', '六'];
    this.calculateEmptyGrids(cur_year, cur_month);
    this.calculateDays(cur_year, cur_month);
    //获取当前用户当前任务的签到状态
    // this.onGetSignUp();
    this.setData({
      cur_year,
      cur_month,
      weeks_ch
    })
  },
  shouqun() {
    wx.navigateTo({
      url: '/page_zhu/shou/shou?sta=66',
    })
    this.setData({
      isshou: false
    })
  },
  // 判权
  panquan() {
    var token = wx.getStorageSync("token");
    wx.request({
      url: yuming + 'shop/shop_staff_yaoshi_power',
      data: {
        shopId: wx.getStorageSync('shopIds')
      },
      header: {
        "content-type": 'application/x-www-form-urlencoded',
        token: token ? token : "",
        source: 'EabEnd'
      },
      method: 'POST',
      success: (res) => {
        wx.hideLoading({
          success: (res) => {},
        })
        var pages = getCurrentPages()
        var currentPage = pages[pages.length - 1]
        var url = currentPage.route //当前页面url
        var options = currentPage.options
        // console.log(url)
        // console.log(options)
        if (res.data.code == 202) {
          var that = this
          wx.showModal({
            title: '需要授权哦~',
            cancelText: '取消',
            confirmText: '确定',
            success: function (res) {
              if (res.confirm) {
                console.log("确定")
                that.setData({
                  isshou: false
                })
                wx.navigateTo({
                  url: '/page_zhu/shou/shou?sta=66',
                })
              } else {
                that.setData({
                  isshou: true
                })
                console.log("取消")
              }
            }
          })
        }
        // else {
        //   this.shouquan();
        // }
        // if (res.data.code == 200) {
        this.setData({
          bangd: res.data.data.isBangding
        })
        console.log(this.data.bangd)
        if (this.data.bangd == 0) {
          this.gobangd()
        }
        if (this.data.bangd == 1) {
          this.yaoinfo()
        }
        // }
        wx.hideLoading();
      },
      fail: (error) => {}
    })
    // this.myRequest(yuming + 'shop/shop_staff_yaoshi_power', {
    //   shopId: wx.getStorageSync('shopIds')
    // }, 'POST').then(res => {
    //   console.log(res)

    // })
  },
  // 去绑定
  gobangd() {
    let that = this
    wx.showModal({
      title: '提示',
      content: '您还没有绑定哦，快去绑定吧~',
      success(res) {
        if (res.confirm) {
          that.bound()
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  bound() {
    wx.navigateTo({
      url: '/page_other/zdysbd/zdysbd',
    })
  },

  

  //  重构打卡逻辑
  // 获取经纬度 
  getLocation(){
    var that = this
    wx.getLocation({
      type: 'wgs84',
      success: (res) => {
        console.log(res)
        that.setData({
          dakalatitude: res.latitude,//纬度
          dakalongitude: res.longitude,//经度
        })
    
        this.getAddress();
      
      },
      fail: (err) => {
        var err = JSON.stringify(err)
        console.log(err)
        that.wxsT(err)
      }
    })
  },
  // 地址解析经纬度获取详细地址信息
  getAddress(){
    let that = this;
    let location = '' + that.data.dakalongitude + ',' + that.data.dakalatitude + ''
    console.log('经纬度',location)
    let myAmapFun = new amapFile.AMapWX({
      key: config.config.key
    });
    myAmapFun.getRegeo({
      location:location , //location的格式为'经度,纬度'
      success: function (data) {
        console.log(data)
        that.setData({
          NowAddress: data[0].regeocodeData.formatted_address
        })
      },
      fail: function (err) {
        var err = JSON.stringify(err)
        that.wxsT(err)
      }
    })
  },
  //  是否授权登录----
  empower() {
      var that = this
      var token = wx.getStorageSync("token");
      wx.request({
        url: yuming + 'shop/shop_staff_yaoshi_power',
        data: {
          shopId:that.data.shopId
        },
        header: {
          "content-type": 'application/x-www-form-urlencoded',
          token: token ? token : "",
          source: 'EabEnd'
        },
        method: 'POST',
        success: (res) => {
          if (res.data.code == 202) {
            var that = this
            wx.showModal({
              title: '需要授权哦~',
              cancelText: '取消',
              confirmText: '确定',
              success: function (res) {
                if (res.confirm) {
                  console.log("确定")
                  that.setData({
                    isshou: false  
                  })
                  wx.navigateTo({
                    url: '/page_zhu/shou/shou?sta=66',
                  })
                } else {
                  that.setData({
                    isshou: true  
                  })
                  console.log("取消")
                }
              }
            })
          }else{
            var  isBangding = res.data.data.isBangding 
            this.setData({
              bangd:isBangding  //是否授权绑定  授权=1  未授权=0
            })
            if (isBangding == 0) {  
              this.gobangd()//去绑定
            }
            if (isBangding== 1) {  // 授权=1  预处理打卡信息
              this.getyaoUserInfo()//获取当前登录药师的信息
            //   this.getshopjwd()   //获取店铺经纬度  用来打卡的时候获取经纬度并计算距离是否在打卡范围内  //页面刚开始的时候已经开始获取自己的定位
              // this.getRequestJuli() //获取店铺可打卡范围  this.fanwei并计算出是否在打卡范围内
            }
          }
         
          wx.hideLoading();
        },
        fail: (error) => {}
      })  
    },
      // 药师信息
  getyaoUserInfo() {  
    this.myRequest(yuming + 'shop/shop_staff_yaoshi_user ', {
      shopId: wx.getStorageSync('shopIds')
    }, 'POST').then(res => {
       console.log('获取药师信息',res)
      this.setData({
        yaoshi: res.data.data,
        id: res.data.data.id
      })
    //   由于某些接口涉及到id所以在此处预处理所有需要用到的信息
      this.getshopjwd()//获取店铺信息
      if(this.data.cutterIndex==0){
         this.getdkList();  // 获取打卡记录  用来展示列表
      }
      this.IsSignin();  
    })
  },
    //查询当前是否允许打卡 查询签到次数   当天打卡记录   
    IsSignin() {
      let that = this
      this.myRequest(yuming + 'shop/shop_staff_yaoshi_notOryes', {
        shopId: wx.getStorageSync('shopIds'),
        staffid: that.data.id
      }, 'POST').then(res => {
        if (res.data.code == 200) {
            that.setData({
            dayList: res.data.dayList,
            jilulist: res.data.data,  //打卡记录
            daySign: res.data.daySign, //打卡次数
            isQian: res.data.isQian//当前是否允许签到
          })
          var isQian  = res.data.isQian
          if(isQian){// 是否允许签到 允许签到  还要计算打卡范围是否满足
            console.log('判断范围函数中使用',isQian)//在范围但是4个小时前已经打过卡
            this.fanwei()   //获取店铺经纬度并计算距离是否在打卡范围内  //onLoad的时候已经开始获取了自己的定位
          }else{//不允许签到  因为后台只判断了4个小时之内不允许签到  所以如果是不允许直接显示倒计时
               //   判断最后打卡时间显示倒计时
          var jieshutime = res.data.fourTime
          if (this.data.daySign == 1 && !this.data.isQian) {
            if(res.data.dayList.length>0){
                var zongtim = res.data.dayList[0].createtime
             }
            this.setData({
              zongtim: zongtim,  //首次打卡时间
              jieshutime: jieshutime, //结束打卡时间
            })
            this.countTime()
          }
          }
          this.onJudgeSign();  //匹配判断当月与当月哪些日子签到打卡
           
        
  
        }
      })
    },
    // 计算倒计时函数
  countTime() {
    let daysaa, hours, minutes, seconds;
    // let nowDate = this.data.jieshutime;
    // console.log(nowDate)
    let that = this;
    let now = Date.parse(new Date())
    let end = this.data.jieshutime; //设置截止时间
    // console.log("开始时间：" + now, "截止时间:" + end);
    let leftTime = end - now; //时间差 
    if (leftTime >= 0) {
      daysaa = Math.floor(leftTime / 1000 / 60 / 60 / 24);
      hours = Math.floor(leftTime / 1000 / 60 / 60 % 24);
      minutes = Math.floor(leftTime / 1000 / 60 % 60);
      seconds = Math.floor(leftTime / 1000 % 60);
      seconds = seconds < 10 ? "0" + seconds : seconds
      minutes = minutes < 10 ? "0" + minutes : minutes
      hours = hours < 10 ? "0" + hours : hours
      that.setData({
        countdown: hours + ":" + minutes + ":" + seconds,
        daysaa,
        hours,
        minutes,
        seconds
      })
      // console.log(that.data.countdown)
      //递归每秒调用countTime方法，显示动态时间效果
      setTimeout(that.countTime, 1000);
    } else {
      that.setData({
        countdown: '已截止'
      })
    }
  },
  //打卡
  startDaka(){
    this.fanwei()
    let that = this;
    // 判断是否可以打卡
    var buttonClicked = this.data.buttonClicked
    if(!buttonClicked){//如果不可以打卡
      this.wxsT('打卡时间需间隔4个小时')
      return false
    }


    this.myRequest(yuming + 'shop/shop_staff_yaoshi_tosign', {
      shopId: wx.getStorageSync('shopIds'),
      staffid: that.data.id,
      lat: that.data.dakalatitude,
      lng: that.data.dakalongitude,
      signaddress: that.data.NowAddress
    }, 'POST').then(res => {
      // wx.showToast({
      //   title: res.data.msg,
      //   icon: 'none'
      // })
      this.wxsT(res.data.msg)
      if (res.data.code == 200) {
        setTimeout(() => {
          this.setData({
            buttonClicked: false
          })
        }, 500)
        // this.IsSignin();//更新打卡次数
        // this.getdkList();//更新打卡列表
        // 打卡成功之后重新更新当前页面的所有数据
        this.getyaoUserInfo()
      }
    })
   
  },
  // 开启或关闭未打卡说明弹窗
  Isweida(){
    var  isbu = this.data.isbu
    this.setData({
      isbu: !isbu
    })
  },
  
  
   // 提示showToast
   wxsT(title){
    wx.showToast({
      title: title,
      icon: 'none',
      duration:2000,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    // this.panquan()
    this.empower()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

// onShareAppMessage: function (res) {
//   console.log('onShareAppMessage',res);
//   return {
//     title: '自定义标题',
//     path: '/page_other/zdysdk2/zdysdk2?scene=281',
//   }
// },
})